package inputs;

/**
 * Abstract class to define Input behavior.
 * 
 * An input has a value that can be updated using the abstract Update() function.
 * This function is protected so it can only be called by Input objects.
 * Other objects can use the public UpdateInput() function, which checks to see if
 * the current data is invalid. If it is, it calls Update(), otherwise it doesn't.
 * This behavior makes sure that we don't accidentally call Update() twice in one
 * frame/tick.
 * 
 *  To make the data invalid, an outside object can call Invalidate() which simply
 *  flags the object to actually update on the next call.
 *  
 *  This object also contains a min and max to inform other objects of the range of
 *  its output data. These should be updated as the concrete child classes see fit.
 *  
 *  Outside objects can access the appropriate values through:
 *  	-getMin()
 *  	-getMax()
 *  	-getValue()
 * 
 * @author Dylan James
 *
 */
public abstract class Input {
	protected int min, max;
	protected boolean invalid = true;
	
	/**
	 * Protected constructor so it can only be called from other Inputs.
	 */
	protected Input()
	{
		min = 0;
		max = 0;
	}
	
	/**
	 * Constructs an input given a min and max value
	 * 
	 * @param min
	 * @param max
	 */
	public Input(int min, int max)
	{
		this.min = min;
		this.max = max;
	}
	
	public int getMin()
	{
		return min;
	}
	
	public int getMax()
	{
		return max;
	}
	
	/**
	 * Sets the minimum value of this input
	 * @param min
	 */
	public void setMin(int min)
	{
		this.min = min;
	}
	
	/**
	 * Sets the maximum value of this input
	 * @param max
	 */
	public void setMax(int max)
	{
		this.max = max;
	}
	
	/**
	 * Updates the input if it is marked as invalid.
	 */
	public void UpdateInput()
	{
		if (invalid)
		{
			this.Update();
			invalid = false;
		}
	}
	
	/**
	 * Marks this input as invalid, causing it to update on the next call.
	 */
	public void Invalidate()
	{
		this.invalid = true;
	}
	
	/**
	 * 'Ticks' this input, causing it to update
	 */
	protected abstract void Update();
	public abstract int getValue();
}
